﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.DataAccess.Model.Project.Entrepot;
using Core.Framework.Util;
using Core.IBusiness.IEntrepotModule;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Core.Web.Controllers.Entrepot
{
    /// <summary>
    /// 库存管理
    /// </summary>
    [Route(".v1/Entrepot/[controller]")]
    [ApiController]
    [ApiVerification(IBusiness.IProjectModule.Model.APIServiceEnum.Shop)]
    public class ProductSKUController : BaseApiController
    {


        public ProductSKUController(IEntrepot iEntrepot) :
            base(iEntrepot: iEntrepot)
        { }

        /// <summary>
        /// 注册产品库存
        /// </summary>
        /// <param name="skus">修改参数模型</param>
        /// <returns></returns>
        [HttpPost]
        public IResult POST(List<ProductSku> skus)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iEntrepot.ProductSKU(skus));
                }, skus.IsValid(IsValidEnum.reg));
        }



        /// <summary>
        /// 修改库存
        /// </summary>
        /// <param name="model">提交参数</param>
        /// <returns></returns>
        [HttpPut]
        public IResult Put(EntrepotRequest model)
        {
            return this.ExecMethod(
                () => {
                    return this.Result(this.iEntrepot.UpdateSKU(model.sku_key, model.count_stock));
                },
                new Tuple<bool, string>(model.sku_key > 0, "params: key is null"),
                new Tuple<bool, string>(model.count_stock > 0, "params: key is null"));
        }



    }
}